﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Script.Game.OOP
{
    public class Item
    {
        public Vector3 Pos;
        public Color Color;
        public Vector3 Rotate;
        public GameObject GameObject;

        public Item(Vector3 pos,Color color,Vector3 rotate)
        {
            Pos = pos;
            Color = color;
            Rotate = rotate;
        }
    }
    public class TestGame:MonoBehaviour
    {
        public List<Item> ItemList;

        private void Awake()
        {
            ItemList = new List<Item>();
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    var item = new Item(new Vector3(2*i,0,2*j),j %2 == 0 ?Color.blue:Color.red,Vector3.up);
                    ItemList.Add(item);
                } 
            } 
        }

        private void Start()
        {
            var go = Resources.Load("Prefabs/Cube") as GameObject;
            for (int j = 0; j < ItemList.Count; j++)
            {
                var goIns = Instantiate(go);
                ItemList[j].GameObject = goIns;
            } 
        }

        private void Update()
        {
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    var item = ItemList[i * 100 + j];
                    item.GameObject.transform.position = item.Pos;
                    item.GameObject.transform.Rotate(item.Rotate);
                    item.GameObject.GetComponent<MeshRenderer>().material.color = item.Color;
                } 
            }
        }
    }
}